home *** CD-ROM | disk | FTP | other *** search
/ BCI NET / BCI NET Dec 94.iso / archives / programming / utilities / easyproc2.lha / EasyProcess / launch / WaitProcs.c < prev   
Encoding:
C/C++ Source or Header  |  1992-11-05  |  1.7 KB  |  81 lines

  1. #include "Launch.h"
  2. #include "LaunchPriv.h"
  3.  
  4.  
  5. /*
  6.  *    NAME
  7.  *        WaitProcesses -- wait for all child processes to end.
  8.  *
  9.  *    SYNOPSIS
  10.  *        WaitProcesses ()
  11.  *
  12.  *        void WaitProcesses (void);
  13.  *
  14.  *    FUNCTION
  15.  *        Wait until all processes that were launched by this process
  16.  *        are finished.  You MUST call this at the end of your program
  17.  *        since it also cleans up some memory allocation when there are
  18.  *        no more child.
  19.  *
  20.  *    DESCRIPTION
  21.  *        Scan the process pair list and for each process that we are
  22.  *        the parent of we wait until it ends and we remove the process
  23.  *        pair and free the memory.
  24.  *
  25.  *        When all process pair have been scanned, we free the parent's
  26.  *        signal bit and try to free the list.
  27.  *
  28.  *        The fact that we wait while we scan the list does not matter
  29.  *        since the list cannot go away (it contain at least one pair,
  30.  *        ours) and the next pointer is only used AFTER we return from
  31.  *        the wait.
  32.  *
  33.  *    INPUT
  34.  *        None.
  35.  *
  36.  *    OUTPUT
  37.  *        None.
  38.  *
  39.  *    HISTORY
  40.  *        1992/09/06    Pierre Baillargeon        Creation
  41.  *        1992/09/07    Pierre Baillargeon        Update
  42.  *                    Made faster and simpler.
  43.  *
  44.  *    SEE ALSO
  45.  *        WaitProcess(), WaitProcFunc()
  46.  */
  47.  
  48. void WaitProcesses (void)
  49. {
  50.     struct ProcPair *pp, *ppn;
  51.     struct Process *Proc;
  52.     LONG Bit;
  53.  
  54.     Bit = -1L;
  55.     Proc = (struct Process *)FindTask (NULL);
  56.  
  57.     Forbid ();
  58.     for (pp = (struct ProcPair *)ProcPairList->lh_Head; pp->pp_Node.ln_Succ; pp = ppn)
  59.     {
  60.         if (Proc == pp->pp_Parent)
  61.         {
  62.             Bit = pp->pp_ParentBit;
  63.             while (pp->pp_ChildEntry)
  64.             {
  65.                 Wait (1L << Bit | KILL_PROCESS_FLAG);
  66.             }
  67.             ppn = (struct ProcPair *)pp->pp_Node.ln_Succ;
  68.             Remove (&pp->pp_Node);
  69.             FreeMem (pp, sizeof (struct ProcPair));
  70.         }
  71.         else
  72.         {
  73.             ppn = (struct ProcPair *)pp->pp_Node.ln_Succ;
  74.         }
  75.     }
  76.  
  77.     FreeParentSignal (Bit);
  78.     FreeProcPairList ();
  79.     Permit ();
  80. }
  81.